package knowledgebase;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.ReadWrite;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.tdb.TDBFactory;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author mary
 */
public class QueryYAGOTDB {
    
    public static void main(String[] args){
    		String pathToYAGO="/Users/mary/Documents/Education/PhD/YAGO/yago2core_jena_20120109";
        queryYago(pathToYAGO);
    }
    
    static void queryYago(String dir){
        
        
       
        Dataset dataset = TDBFactory.createDataset(dir) ;
        
        Model tdb = dataset.getDefaultModel();
        
        String querySring = "select ?s ?p ?o where {?s ?p ?o} limit 1000";  // query for YAGO
        
        dataset.begin(ReadWrite.READ);
        
        Query query = QueryFactory.create(querySring);
        QueryExecution qexec = QueryExecutionFactory.create(query, dataset);
        ResultSet results = qexec.execSelect();
        
        ResultSetFormatter.out(results) ;
        
        qexec.close();
        dataset.end();
        
    }
    
    
    
}
